<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>添加管理员</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
       <!--<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>-->
        <script type="text/javascript" src="./js/index.js"></script>
        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

    </head>  
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>红包ID
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="id"  name="id" required=""  readonly="true"
                          autocomplete="off" class="layui-input ">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>红包ID
                      </div>
                  </div>
                  
				  
				 
				  
                
                   
                       
                      </div>
					  
					  <div class="layui-form-item" id="manjian" style="display: none;">
					      <label for="L_pass" class="layui-form-label">
					          <span class="x-red">*</span>门槛金额
					      </label>
					      <div class="layui-input-inline">
					          <input type="text" id="preferentialway" name="preferentialway" required="" 
					          autocomplete="off" class="layui-input">
					      </div>
					      <div class="layui-form-mid layui-word-aux">
					         门槛减金额
					      </div>
					  </div>
                 
                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>优惠面值
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="parvalue" name="parvalue" required="" 
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                         满减金额
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>发放数量
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="totalissued" name="totalissued" required="" 
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
				  <label class="layui-form-label"><span class="x-red">*</span>门槛</label>
				  <div class="layui-input-block">
				    <div id="aaa">
				    	<select id="wu"  onclick="zhanshi()">
				    <option value ="0" >无门槛</option>
				  						 <option value ="1" >有门槛</option>
				    	</select>
				    </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="" onclick="xiugai()">
                          修改
                      </button>
                  </div>
              </form>
            </div>
        </div>
		
    
  </body>

    <script type="text/javascript">
	

var op=document.getElementById("wu").value;
document.getElementById("id").value=getUrlVar("id");
document.getElementById("parvalue").value=getUrlVar("parvalue");
document.getElementById("wu").value=getUrlVar("threshold");
document.getElementById("preferentialway").value=getUrlVar("preferentialway");
document.getElementById("totalissued").value=getUrlVar("totalissued");
function zhanshi(){
	var op=document.getElementById("wu").value;
		var manjian=document.getElementById("manjian");
		
		if(op==1){
		manjian.style.display="block";
		}else if(op==0){
			manjian.style.display="none";
			document.getElementById("preferentialway").value=0;
		
		}
		}
		zhanshi();
   //重新加载js文件
           function loadJs(file)
   {
       var head = $("head").remove("script[role='reload']");
       $("<scri"+"pt>"+"</scr"+"ipt>").attr({ 
       role:'reload',src:file,type:'text/javascript'}).appendTo(head);
   } 
              function getUrlVars(){    var vars = [], hash;
       var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

       for(var i = 0; i < hashes.length; i++)
       {
           hash = hashes[i].split('=');
           vars.push(hash[0]);
           vars[hash[0]] = hash[1];
       }
       return vars;
   }
   
   
   //得到指定参数的value
   function getUrlVar(name){
       return getUrlVars()[name];
   }
   
   function xiugai(){
   	
   	var op=document.getElementById("wu").value;
   	var id=document.getElementById("id").value;
   	
   	var preferentialway=document.getElementById("preferentialway").value;
   	var parvalue=document.getElementById("parvalue").value;
   	var totalissued=document.getElementById("totalissued").value;
   	if(op==0){
   		preferentialway=0;
   	}
   	$.ajax({
   		xhrFields:{withCredentials: true},
   	url: "http://localhost:16111/activity/update",
   	mimeType: "post",
   	data: {
   		id:id,
   		preferentialway:preferentialway,
   		parvalue:parvalue,
   		threshold:op,
   		totalissued:totalissued
   	},
   	dataType: "json",
   	
   		
   	success: function(date){
   		console.log(date);
   		if(date == 1){
   			alert("成功");
   		window.location.href="优惠券管理.html";
   		}else{
   			alert("失败");
   		}
   		
   	},
   	});
   }
   
    </script>
  
</html>